<?php
namespace App\Models\Traits;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\RequestException;

trait Curl
{
    protected function newClient()
    {
        return new Client([
            'timeout' => 2.0
        ]);
    }

    protected function curlGet(string $uri)
    {
        $client = $this->newClient();

        try{
            return $client->get($uri)->getBody()->getContents();
        } catch (ClientException $exception) {
            logger()->error($exception->getRequest()->getUri());
            logger()->error($exception->getResponse()->getStatusCode());
        } catch (RequestException $exception) {
            logger()->error($exception->getMessage());
        }
        return false;
    }
}